package dlally.controller;


import java.awt.event.MouseEvent;
import java.util.Arrays;

import dlally.model.DecisionLinesEvent;
import dlally.model.Edge;
import dlally.view.GameFieldGUI;

public class EdgeController {
	GameFieldGUI gui;
	DecisionLinesEvent model;
	MouseEvent e;
	
	public EdgeController(GameFieldGUI gui, DecisionLinesEvent model, MouseEvent e){
		this.gui = gui;
		this.model = model;
		this.e = e;
	}
	
	public void process(){
		int x = e.getX();
		int y = e.getY();
		int left = (int) Math.ceil((x - 50) / 100.0) - 1;
		if(model.addEdge(new Edge(left, left + 1, y)))
			gui.getPanel().addLine((left * 100) + 50, y, (left * 100) + 150, y);
		if(model.isDone()){
			gui.getLabel().setText("Results: " + Arrays.toString(model.prioritizedChoices()));
			gui.disableMouseListener();
			printResultsToConsole();
		}
		
		
	}
	
	private void printResultsToConsole(){
		String[] answer = model.prioritizedChoices();
		for(int i = 0; i < answer.length; i++)
			System.out.println(answer[i]);
	}

}
